package com.qf.fmmall.controller;


import com.qf.fmmall.entity.ShoppingCart;
import com.qf.fmmall.service.ShoppingCartService;
import com.qf.fmmall.utils.JwtUtils;
import com.qf.fmmall.vo.ResStatus;
import com.qf.fmmall.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/shopcart")
@CrossOrigin
public class ShopCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @RequestMapping(value = "list2",method = RequestMethod.GET)
    @ResponseBody
    public ResultVo list(String token){

        ResultVo vo = new ResultVo();
        if (token==null){
            vo.setCode(ResStatus.NO);
            vo.setMsg("没有提供合法的token");
        }else {
            boolean b = JwtUtils.parsetoken(token);
            if (b){
                //处理购物车业务逻辑

                //返回
                vo.setCode(ResStatus.OK);
                vo.setMsg("查询成功");
                vo.setData("购物车信息");
            }else {
                vo.setCode(ResStatus.NO);
                vo.setMsg("请提供合法的token");
            }
        }
        return vo;
    }


    @RequestMapping(value = "list1",method = RequestMethod.GET)
    @ResponseBody
    public ResultVo list1(){

        ResultVo vo = new ResultVo(ResStatus.OK,"list1 OK",null);
        return vo;
    }

    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("添加购物车接口")
    public ResultVo addShopCart(@RequestBody ShoppingCart shoppingCart){
       return shoppingCartService.addShopCart(shoppingCart);
    }

    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("查询购物车信息接口")
    public ResultVo list(Integer userId){
        return shoppingCartService.listByUserId(userId);
    }

    @RequestMapping(value = "update/{cid}/{cnum}",method = RequestMethod.PUT)
    @ResponseBody
    @ApiOperation("修改购物车信息接口")
    public ResultVo update(@PathVariable("cid") Integer cid,@PathVariable("cnum") Integer cnum){
        return shoppingCartService.update(cid,cnum);
    }

    @RequestMapping(value = "listbycids",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("查询订单商品信息接口")
    public ResultVo listbycids(String cids){
        return shoppingCartService.listbycids(cids);
    }

}
